if(!(-e "tpreimpute1.fam"))
{
	system("mv tpreimpute.fam tpreimpute1.fam");
}
open(BUFF,"tpreimpute1.fam") or die "no file found tpreimpute.fam\n";
open(WRBUFF,">tpreimpute.fam");
open(REM,">remove.fam");
open(ID,"id.txt");
while(<ID>)
{
	chomp($_);
	$_ =~ s/ |\r//g;
	@a=split("\t",$_);
	$hash{$a[3]}="$a[0] $a[1]";
	#print "$a[3]$a[0]$a[1]\n";
}
$rand=1;
while(<BUFF>)
{
	chomp($_);
	@array=split(" ",$_);
	#print $array[1]."$array[2]\n";
	if(exists($hash{$array[1]}))
	{
		print WRBUFF "$hash{$array[1]} $array[2] $array[3] $array[4] $array[5]\n";
	}
	else
	{
		print WRBUFF "$rand $rand $array[2] $array[3] $array[4] $array[5]\n";
		print REM "$rand $rand $array[2] $array[3] $array[4] $array[5]\n";
		$rand++;
	}
}
close(BUFF);
system("cat remove.fam delete_sample_reason_entire_chr.txt > remove1.fam");
system("plink --bfile tpreimpute --remove remove1.fam --transpose --recode --out tpreimpute_final");
